//
//  WYProposalController.m
//  Boss
//
//  Created by admin on 2018/7/3.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYProposalController.h"

@interface WYProposalController ()
@property (strong, nonatomic) IBOutlet UITextView *textView;
@property (strong, nonatomic) IBOutlet UITextField *numberLabel;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *textViewTop;
@property (strong, nonatomic) IBOutlet UIButton *uploadBtn;

@end

@implementation WYProposalController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTextView];
    [self setupUI];
    // Do any additional setup after loading the view from its nib.
}
-(void)setupUI
{
    self.navigationItem.title = @"意见反馈";
    self.view.backgroundColor = [UIColor hexStringToColor:@"#f7f7f7" alpha:1.0];
    self.textViewTop.constant = self.navHeight+10;
    [self.uploadBtn setCornerRadius:5.f];
}
- (void)setupTextView
{
    
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    //placeHolderLabel.text = @"感谢您使用巨牛BOSS APP，您在使用过程中有任何意见或建议请反馈给我们，我们将不断地优化用户体验。";
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    
    paraStyle.alignment = NSTextAlignmentLeft;
    
    paraStyle.lineSpacing = 2.6; //设置行间距
    
    paraStyle.hyphenationFactor = 1.0;
    
    paraStyle.firstLineHeadIndent = 0.0;
    
    paraStyle.paragraphSpacingBefore = 0.0;
    
    paraStyle.headIndent = 0;
    
    paraStyle.tailIndent = 0;
    
    //设置字间距 NSKernAttributeName:@1.5f
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:16.f], NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.8f
                          };
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:@"感谢您使用巨牛BOSS APP，您在使用过程中有任何意见或建议请反馈给我们，我们将不断地优化用户体验。" attributes:dic];
    
    placeHolderLabel.attributedText = attributeStr;
    
    
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = [UIColor hexStringToColor:@"#aaaaaa" alpha:1.0];
//    [self setLabelSpace:placeHolderLabel withValue:placeHolderLabel.text withFont:[UIFont systemFontOfSize:16.f]];
    [placeHolderLabel sizeToFit];
    
    //placeHolderLabel.frame = CGRectMake(16, 10, kScreenWidth-32, self.textView.height);
    [self.textView addSubview:placeHolderLabel];
    placeHolderLabel.font = [UIFont systemFontOfSize:16.f];
    [self.textView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
}
-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font {
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    
    paraStyle.alignment = NSTextAlignmentLeft;
    
    paraStyle.lineSpacing = 2.6; //设置行间距
    
    paraStyle.hyphenationFactor = 1.0;
    
    paraStyle.firstLineHeadIndent = 0.0;
    
    paraStyle.paragraphSpacingBefore = 0.0;
    
    paraStyle.headIndent = 0;
    
    paraStyle.tailIndent = 0;
    
    //设置字间距 NSKernAttributeName:@1.5f
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.8f
                          };
    NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
    label.attributedText = attributeStr;
}
- (IBAction)uploadAction:(id)sender {
    NSString *temp = [self.textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    
    
    if (!self.textView.text.length||!temp.length) {
        self.textView.text = @"";
        [self toast:@"请输入您宝贵的意见"];return;
    }
    WEAKSELF
    [WYHttpServer addFeedBackWithContent:self.textView.text WithContact:self.numberLabel.text SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            
            [weakSelf toast:@"我们已经收到您的宝贵意见"];
        }else{
            [weakSelf toast:errorMessage];
        }
        
        
        
        
    }];
    
    
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
